<template>
    <div class="page">
        <!-- top-nav -->
        <div class="home-menu">
            <div class="container">
                <div class="good-cate">商品分类</div>
                <router-link :to="`${item.url}`" v-for="(item, index) in fixedCategory" :key="index">{{ item.name }}</router-link>
            </div>
        </div>
        <!-- slide -->
        <div class="index-top container td-fss">
            <div class="left td-fc">
                <!-- <div class="type-name td-fcc">
                    <span>商品分类</span>
                </div> -->
                <ul class="left-menu td-f1 td-fc" style="position:relative">
                    <li class="td-f1" :class="clickCurrent == index?'select':''" v-for="(item, index) in category" :key="index" @mouseenter="MouseEnter(index)" @mouseleave="clickCurrent = 100" @click="_cateHandelClick(item.id,index)">
                        <a class="a" @click="_toCategory(index)">{{ item.cate_name }}</a>
                        <div class="fixed" :style="clickCurrent == index?'display:block':'display:none'">
                            <div class="fixed-tit">推荐专区</div>
                            <div class="fixed-list">
                                <div class="fixed-item" v-for="(child,indexs) in item.children" :key="indexs" @click="_toCategory(index,child.id)">
                                    <img :src="child.choose_pic" alt="">
                                    <div>{{child.cate_name}}</div>
                                </div>

                                <div style="width:80px"></div>
                                <div style="width:80px"></div>
                                <div style="width:80px"></div>
                                <div style="width:80px"></div>
                            </div>
                        </div>
                    </li>

                    <!-- <div class="more-cate td-fcc" @click="_toCategory('all')">更多分类</div> -->
                </ul>
            </div>
            <div class="right td-f1">
                <div class="banner">
                    <el-carousel :autoplay="true" :interval="5000" height="380px">
                        <el-carousel-item v-for="item in banner" :key="item.id">
                            <div class="banner-item" @click="handelClickBanner(item.url)">
                                <img :src="item.pic" />
                            </div>
                        </el-carousel-item>
                    </el-carousel>
                </div>
                <div class="new">
                    <div class="tit td-fbc">
                        <span>每日特惠</span>
                        <span class="a more">更多></span>
                    </div>
                    <ul class="new-goods td-f">
                        <li class="new-goods-item" v-for="item in reduceData" :key="item.id" @click="_goGoodsDetail(item)">
                            <div class="img">
                                <img :src="item.image" />
                                <!-- <div class="label-yh td-fcc">满减</div> -->
                            </div>
                            <div class="goods-info td-fcc td-fc">
                                <div class="goods-name ellipsis">{{ item.store_name }}</div>
                                <div class="price">￥{{ item.price }}</div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <!-- goods list -->
        <div class="goodsList" ref="goodsList">
            <div class="container">
                <!-- preferential -->
                <!-- <div class="preferential">
                    <div class="tit td-fbc">
                        <span>每日特惠</span>
                        <span class="a more" @click="$router.push('/discount')">更多></span>
                    </div>
                    <ul class="td-fbs">
                        <li v-for="item in discountData" :key="item.id" @click="_goGoodsDetail(item)">
                            <img :src="item.image" />
                            <div class="name ellipsis">{{ item.store_name }}</div>
                            <div class="desc ellipsis">{{ item.store_info }}</div>
                        </li>
                    </ul>
                </div> -->
                <div class="tit">
                    <!-- <img src="../assets/second_icon/left_fire_icon.png" class="fire-left-icon" alt=""> -->
                    <div class="tit-text">热销商品</div>
                    <!-- <img src="../assets/second_icon/right_fire_icon.png" alt="" class="fire-right-icon"> -->
                </div>
                <ul class="list">
                    <li v-for="(item, index) in productList" :key="index">
                        <div class="goods-box" @click="_goGoodsDetail(item)">
                            <img class="goods-img" :src="item.image" @click="_goGoodsDetail(item)" />
                            <div class="goods-name ellipsis" :title="item.store_name">{{ item.store_name }}</div>
                            <div class="goods-price td-fbc">
                                <span>¥{{ item.price }}</span>
                                <img :src="$global.Image.icon_cart" @click.stop="_showGoodsInfo(item)" />
                            </div>
                        </div>
                    </li>
                    <div class="nodata" v-if="productList.length == 0">
                        <img :src="$global.Image.noGood" />
                    </div>
                </ul>
            </div>
        </div>
        <div class="pagination-box">
            <el-pagination background layout="prev, pager, next" @current-change="pageChange" :page-size="limit" :total="count">
            </el-pagination>
        </div>
        <!-- add cart -->
        <v-add-cart ref="addCart"></v-add-cart>
    </div>
</template>

<script>
import { getPcHomeData,getFooter,getPcBanner } from "@api/public";
import { getCategory } from "@api/store";
import { formatSelectData } from "@utils/format";
import { getProducts } from "@api/store";
import addCart from "@components/addCart";

export default {
    components: {
        "v-add-cart": addCart,
    },
    data() {
        return {
            fixedCategory: [
                { name: "采购清单", url: "/stockList" },
                { name: "需求上架", url: "/demandList" },
                { name: "生产代工", url: "/oemIndex" },
                { name: "非标定制", url: "/noStandCustomIndex" },
                { name: "设备报修", url: "/deviceServiceIndex" },
                { name: "运维外包", url: "/outSourceIndex" },
                { name: "技工改造", url: "/techChangeIndex" },
                { name: "意见反馈", url: "/feedbackIndex" },
            ],
            clickCurrent: 100,
            category: [], // 首页分类
            activeIndex: 0, // 当前首页分类索引
            activeCate: {}, // 单签收页分类
            secondCate: [], // 当前二级分类
            selectCate: [], // 首页分类选择
            discountData: [], // 每日特惠
            reduceData: [], // 满减优惠
            hotBrandtData: [], // 热门榜单
            hotBrandtIndexId: "",
            hotBrandtImg: "",
            productList: [], // 产品列表
            where: {
                // 筛选
                page: 1,
                limit: 12,
                keyword: "",
                cid: 0, //一级分类id
                sid: 0, //二级分类id
                news: 0,
                priceOrder: "",
                salesOrder: "",
            },
            count: 0, // 总条数
            price: 0,
            stock: 0,
            nows: false,
            timer: null,
            timerNum: 0,
            banner: [],
        };
    },
    mounted() {
        localStorage.removeItem("cIndex");
        localStorage.removeItem("sid");
        this.loadCategoryData();
        let params = {
            page: 1,
            limit: 20,
        };
        getPcBanner().then(res=>{
            console.log(res)
            this.banner = res.data.data;
        })
        getPcHomeData(params).then((res) => {
            this.discountData = res.data.discount.slice(0, 3);
            this.reduceData = res.data.reduce.slice(0, 4);
            this.productList = res.data.recommend_product.data;
        });
    },
    methods: {
        loadCategoryData() {
            getCategory().then((res) => {
                this.category = res.data;
            });
        },
        
        MouseEnter(index) {

            this.clickCurrent = index;
        },
        _toCategory(cIndex, sid) {
            localStorage.setItem("cIndex", cIndex);
            localStorage.setItem("sid", sid);
            this.$router.push("/category");
        },
        //点击事件处理
        _cateHandelClick(id, index) {
            this.where.sid = id;
            // this._getCategoryGoods();
        },
        // 进入商品详情
        _goGoodsDetail(item) {
            this.$router.push("/detail/" + item.id);
        },
        // 显示商品信息
        _showGoodsInfo(item) {
            this.$refs.addCart.show(item.id);
        },
        // 轮播图跳转
        handelClickBanner(url) {
            window.open(url);
        },
    },
};
</script>

<style scoped  lang="scss" scoped>
.page {
    padding-bottom: 60px;
}
.home-menu {
    font-size: 16px;
    border-bottom: solid #eee 1px;
    box-shadow: 0 5px 8px rgba(0, 0, 0, 0.15);
    .container {
        display: flex;
        .good-cate {
            width: 260px;
            height: 70px;
            background: linear-gradient(143deg, #da213d 23%, #da213d 90%);
            font-size: 16px;
            font-weight: bold;
            text-align: center;
            color: #ffffff;
            line-height: 70px;
            text-shadow: 0px 0px 4px #00000080;
        }
        a {
            display: block;
            color: #333;
            margin-left: 50px;
            padding: 24px 0;
            &:nth-of-type(1) {
                margin-left: 40px;
            }
        }
        a:hover {
            color: #da213d;
        }
        .active {
            font-size: 18px;
            color: #014a97;
            font-weight: 600;
        }
    }
}

// index-top
.index-top {
    overflow: hidden;
    // margin-top: 40px;
    // height: 600px;
    .left {
        width: 260px;
        // height: 600px;
        box-sizing: border-box;
        background-color: #eee;
        // border: solid #eee 1px;
        .type-name {
            height: 50px;
            font-size: 18px;
            border-bottom: solid #dbdbdb 1px;
            flex-shrink: 0;
            span {
                padding-left: 6px;
                color: #014a97;
            }
            img {
                display: block;
                width: 25px;
                height: 25px;
            }
        }
        .left-menu {
            position: relative;
            background: #faf5f5;
            .more-cate {
                border-top: solid #fff 1px;
                font-size: 12px;
                color: #014a97;
                height: 30px;
                cursor: pointer;
            }
            .fixed {
                position: absolute;
                z-index: 999;
                top: 0;
                width: 528px;
                background: #fff;
                left: 260px;
                .fixed-tit {
                    font-size: 13px;
                    text-align: center;
                    color: #999999;
                    position: relative;
                    line-height: 60px;
                    &::before {
                        top: 0;
                        bottom: 0;
                        margin: auto 0;
                        position: absolute;
                        left: 148px;
                        content: "";
                        width: 80px;
                        height: 1px;
                        background: linear-gradient(90deg, #e7e7e7, #999999);
                    }
                    &::after {
                        top: 0;
                        bottom: 0;
                        margin: auto 0;
                        position: absolute;
                        right: 148px;
                        content: "";
                        width: 80px;
                        height: 1px;
                        background: linear-gradient(90deg, #999999, #e7e7e7);
                    }
                }
                .fixed-list {
                    display: flex;
                    flex-wrap: wrap;
                    justify-content: space-between;
                    padding: 0 30px;
                    box-sizing: border-box;
                    .fixed-item {
                        width: 80px;
                        margin-bottom: 40px;
                        cursor: pointer;
                        img {
                            width: 63px;
                            height: 63px;
                            margin: 0 auto;

                            display: block;
                        }
                        div {
                            text-overflow: -o-ellipsis-lastline;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            display: -webkit-box;
                            -webkit-line-clamp: 1;
                            -webkit-box-orient: vertical;
                            margin-top: 9px;
                            font-size: 14px;
                            text-align: center;
                            color: #333333;
                        }
                    }
                }
            }
            li {
                // position: relative;
                padding: 16px 17px;
                // border: 1px dashed #dbdbdb;
                // border-top: solid #fff 1px;
                text-align: center;
                border-bottom: dashed #dbdbdb 1px;
                &::before {
                    content: "";
                    position: absolute;
                    bottom: 0;
                    left: 0;
                    right: 0;
                }
                &:last-child {
                    &::before {
                        border-bottom: 0;
                    }
                }
                .a {
                    font-size: 16px;
                    font-weight: 600;
                    color: #333;
                }
                .second-cate {
                    margin-top: 10px;
                    // height: 10px;
                    overflow: hidden;
                    span {
                        // white-space: nowrap;
                        padding-right: 20px;
                        // padding-bottom: 10px;
                        font-size: 14px;
                        color: #666666;
                        cursor: pointer;
                    }
                    span:hover {
                        color: #da213d;
                    }
                }
            }
            li.select {
                background: #ffffff;
                border-bottom: 0;
            }
        }
    }
    .right {
        margin-left: 24px;
        margin-top: 26px;
        box-sizing: border-box;
        .banner {
            width: 916px;
            height: 370px;
            img {
                display: block;
                width: 950px;
                height: 370px;
                object-fit: cover;
            }
            ::v-deep .el-carousel__arrow--left {
                left: 8px;
            }
            ::v-deep .el-carousel__arrow--right {
                right: 8px;
            }
            ::v-deep .el-carousel__arrow {
                background: none;
                cursor: pointer;
                i {
                    font-size: 40px;
                    color: #666;
                }
            }
            ::v-deep .el-carousel__indicator--horizontal .el-carousel__button {
                width: 10px;
                height: 10px;
                border-radius: 100%;
                background: #d8d8d8;
            }
            ::v-deep .el-carousel__indicator.is-active button {
                background: rgba(255, 255, 255, 0.69);
            }
            ::v-deep .el-carousel__indicators--horizontal {
                bottom: 25px;
            }
        }
        .new {
            display: flex;
            width: 100%;
            flex-direction: column;
            .tit {
                font-size: 16px;
                line-height: 80px;
                font-weight: bold;
                text-align: left;
                color: #333333;
            }
            .more {
                margin-right: 15px;
                font-size: 16px;
                text-align: right;
                color: #999999;
            }
        }
        .new-goods {
            background-color: #fff;
            display: flex;
            justify-content: space-between;
            .new-goods-item {
                width: 222px;
                display: flex;
                flex-direction: column;
                justify-content: space-around;
                align-items: center;
                cursor: pointer;
                .img {
                    height: 222px;
                    // position: relative;
                    img {
                        display: block;
                        width: 100%;
                        height: 222px;
                        object-fit: cover;
                    }
                    // .label-yh {
                    //     width: 50px;
                    //     height: 24px;
                    //     box-sizing: border-box;
                    //     padding: 10px 0;
                    //     font-size: 14px;
                    //     font-weight: 600;
                    //     color: #fff;
                    //     position: absolute;
                    //     top: 0;
                    //     right: 0;
                    //     background-color: #DA213D;
                    //     text-align: center;
                    //     line-height: 1.2;
                    //     border-radius: 0 0 0 4px;
                    // }
                }
                .goods-info {
                    margin-top: 15px;
                    height: 60px;
                    width: 100%;
                    z-index: 1;
                    background-color: rgba(255, 255, 255, 0.8);
                    .goods-name {
                        font-size: 14px;
                        color: #333333;
                        width: 80%;
                        text-align: center;
                    }
                    .price {
                        margin-top: 5px;
                        font-size: 16px;
                        font-weight: bold;
                        color: #da213d;
                    }
                }
            }
            // .new-goods-item:after {
            //     content: "";
            //     height: 4px;
            //     width: 100%;
            //     position: absolute;
            //     bottom: 0;
            //     left: 0;
            //     z-index: 2;
            // }
            // .new-goods-item:hover::after {
            //     background: #DA213D;
            // }
        }
    }
}

// preferential
.preferential {
    margin-bottom: 40px;
    .tit {
        font-size: 18px;
        font-weight: 700;
        color: #333333;

        .more {
            font-size: 14px;
            color: #999;
            font-weight: normal;
            cursor: pointer;
        }
    }
    ul {
        margin-top: 20px;
        li {
            width: 32%;
            text-align: center;
            cursor: pointer;
            img {
                display: block;
                width: 100%;
                height: 225px;
                object-fit: cover;
            }
            .name {
                font-size: 16px;
                font-weight: 600;
                color: #666;
                margin-top: 10px;
            }
            .desc {
                font-size: 14px;
                color: #999;
                margin-top: 10px;
            }
        }
    }
}

// goods list
.goodsList {
    padding-top: 50px;
    .tit {
        font-size: 18px;
        font-weight: 700;
        color: #333333;
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        padding-top: 40px;
        border-top: 1px solid #dbdbdb;
        .fire-left-icon {
            width: 80px;
            height: 47px;
        }
        .tit-text {
            font-size: 28px;
            font-weight: bold;
            text-align: center;
            margin: 0 22px;
            color: #333333;
        }
        .fire-right-icon {
            width: 80px;
            height: 47px;
        }
    }
    .list {
        overflow: hidden;
        min-height: 410px;
        li {
            margin-top: 50px;
            float: left;
            border-top: solid #eee 1px;
            width: 20%;
            box-sizing: border-box;
            border-bottom: solid #eee 1px;
            border-left: 1px solid #eee;
            padding: 0 0 18px;
            &:nth-child(5n) {
                border-right: solid #eee 1px;
            }
            .goods-box {
                // padding: 0 15px;
                .goods-img {
                    width: 100%;
                    height: 280px;
                    display: block;
                    cursor: pointer;
                    object-fit: cover;
                }
                .goods-name {
                    margin: 0 15px;
                    font-size: 16px;
                    color: #333;
                    height: 30px;
                    line-height: 30px;
                    margin-top: 10px;
                    cursor: pointer;
                }
                .goods-price {
                    margin: 0 15px;
                    // margin-top: 10px;
                    span {
                        font-size: 16px;
                        font-weight: 600;
                        color: #da213d;
                    }
                    img {
                        display: block;
                        width: 23px;
                        height: 23px;
                        cursor: pointer;
                    }
                }
            }
        }
        // li:hover {
        //     background-color: #f8f8f8;
        // }
        // li:nth-child(4n + 4) {
        //     border-right: none;
        // }
    }
}
.pagination-box {
    margin: 40px auto 0;
    width: 1200px;
    border-top: 1px solid #dbdbdb;
    padding-top: 40px;
}
</style>
